﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoDB.Bson;

namespace MongoServices
{
	/// <summary>
	/// The base &quot;Read Only&quot; repository.
	/// </summary>
	/// <typeparam name="T">The MongoServices model to be used by this repository.</typeparam>
	public abstract class ReadOnlyRepository<T> : MongoServicesRepository<T>, IReadOnlyRepository<T>
		where T : MongoServicesModel
	{
		#region Public Methods
		/// <summary>
		/// Gets a collection of the <see cref="MongoServicesModel"/> from the mongoDB database.
		/// </summary>
		/// <returns>An enumerable list of the <see cref="MongoServicesModel"/>s.</returns>
		public IEnumerable<T> GetAll()
		{
			return Collection.FindAllAs<T>();
		}

		/// <summary>
		/// Gets one <see cref="MongoServicesModel"/> from the mongoDB database.
		/// </summary>
		/// <param name="id">The &quot;Id&quot; of the document to be retrieved.</param>
		/// <returns>The selected <see cref="MongoServicesModel"/>.</returns>
		public T GetById(ObjectId id)
		{
			return Collection.FindOneByIdAs<T>(id);
		}
		#endregion
	}
}
